package tasks.task06;

import info.clearthought.layout.TableLayout;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class extra extends JPanel {

    public static int i = 10;
    private static boolean goRight = true;

    public void paintComponent(final Graphics g) {

        g.setColor(Color.WHITE);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(Color.BLACK);

        g.fillOval(50 + i, 50 + i, 50 + i, 50 + i);
    }

    public static void main(final String[] args) {

        JFrame frame = new JFrame("ExtraTask");
        frame.setBounds(0, 0, 640, 480);
        double size[][] = {{TableLayout.FILL,}, {TableLayout.FILL}};

        frame.setLayout(new TableLayout(size));
        frame.setResizable(false);

        final extra f = new extra();
        frame.add(f, "0,0");

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        Timer t = new Timer(50, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                f.repaint();

                if (i > 20)
                    goRight = false;
                if (i < 5)
                    goRight = true;

                if (goRight)
                    i = i + 5;
                else
                    i = i - 5;

            }
        });
        t.start();
    }

}
